unit CariKontrol;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, FormClass, XPMan, StdActns, ActnList, DB, ADODB, StdCtrls, Mask,
  wwdbedit, ExtCtrls, Grids, Wwdbigrd, Wwdbgrid, Buttons, siComp;

type
  TfmCariKontrol = class(TfmFormClass)
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    grdPrgCariList: TwwDBGrid;
    grdUnityCariList: TwwDBGrid;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Carikodu: TwwDBEdit;
    FirmaAdi: TwwDBEdit;
    dsaqPrgCariList: TDataSource;
    dsUnityCariList: TDataSource;
    aqPrgCariList: TADOQuery;
    aqUnityCariList: TADOQuery;
    btListele: TBitBtn;
    Label3: TLabel;
    UnityCarikod: TwwDBEdit;
    acListele: TAction;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure grdPrgCariListTitleButtonClick(Sender: TObject;
      AFieldName: string);
    procedure acListeleExecute(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fmCariKontrol: TfmCariKontrol;

implementation
uses data, UnitOrtak, ana1;
{$R *.dfm}

procedure TfmCariKontrol.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
  fmCariKontrol := nil;
end;

procedure TfmCariKontrol.grdPrgCariListTitleButtonClick(Sender: TObject;
  AFieldName: string);
begin
  inherited;
  if Pos('ASC', ((Sender as TwwDBGrid).DataSource.DataSet as TADOQuery).Sort) > 0 then
    ((Sender as TwwDBGrid).DataSource.DataSet as TADOQuery).Sort := AFieldName + ' DESC'
  else
    ((Sender as TwwDBGrid).DataSource.DataSet as TADOQuery).Sort := AFieldName + ' ASC';
end;

procedure TfmCariKontrol.acListeleExecute(Sender: TObject);
begin
  inherited;
  OpenQueryOnDataSet('Select Carikodu,FirmaAdi,UnityCarikod,Aktif From Cari Where 1=1 ' +
    ifthen(Trim(Carikodu.Text) <> '', ' and Carikodu Like "' + Trim(Carikodu.Text) + '%"', '') +
    ifthen(Trim(FirmaAdi.Text) <> '', ' and FirmaAdi Like "' + Trim(FirmaAdi.Text) + '%"', '') +
    ifthen(Trim(UnityCarikod.Text) <> '', ' and UnityCarikod = ' + Trim(UnityCarikod.Text), '')
    , aqPrgCariList);

//  OpenQueryOnDataSet('Select CODE,DEFINITION_,LOGICALREF From unity_cari Where 1=1 ' +
//    ifthen(Trim(Carikodu.Text) <> '', ' and CODE Like "' + Trim(Carikodu.Text) + '%"', '') +
//    ifthen(Trim(FirmaAdi.Text) <> '', ' and DEFINITION_ Like "' + Trim(FirmaAdi.Text) + '%"', '') +
//    ifthen(Trim(UnityCarikod.Text) <> '', ' and LOGICALREF = ' + Trim(UnityCarikod.Text), '')
//    , aqUnityCariList);
end;

end.
